/*
 * LEDDisplay.cpp
 *
 * This class models the LED Display that displays the
 * all the data provided by the cyclometer device
 *
 * Author: Zachary Masiello
 * Author: Peter-John Rowe
 */

#include <unistd.h>

#include "LEDDisplay.h"

// Constructor
LEDDisplay::LEDDisplay(SegmentPort *newSegmentPort, AnodePort *newAnodePort)
{
	segmentPort = newSegmentPort;
	anodePort = newAnodePort;
	display0 = 0;
	display1 = 0;
	display2 = 0;
	display3 = 0;
}

// Destructor
LEDDisplay::~LEDDisplay()
{
	// TODO Auto-generated destructor stub
}

/**
 * Sets the display values for the next output that should be displayed
 *
 * 0-9 = 0-9;
 * 10, 20, 30... = 1. 2. 3. ...
 * 11 = 0.
 * 12 = blank
 * 13 = .
 */
void LEDDisplay::setDisplay(int newDisplay3, int newDisplay2, int newDisplay1, int newDisplay0)
{
	display3 = newDisplay3;
	display2 = newDisplay2;
	display1 = newDisplay1;
	display0 = newDisplay0;
}

// Controls Display output
void* LEDDisplay::run(LEDDisplay * ledDisplay)
{
	while(true)
	{
		ledDisplay->anodePort->output(0);
		ledDisplay->segmentPort->output(ledDisplay->display0);
		usleep(5);

		ledDisplay->anodePort->output(1);
		ledDisplay->segmentPort->output(ledDisplay->display1);
		usleep(5);

		ledDisplay->anodePort->output(2);
		ledDisplay->segmentPort->output(ledDisplay->display2);
		usleep(5);

		ledDisplay->anodePort->output(3);
		ledDisplay->segmentPort->output(ledDisplay->display3);
		usleep(5);
	}

}
